package borderPatrol.Players;

import java.util.HashMap;
import java.util.Random;

import borderPatrol.Calculators.BorderPatrolTreeUpdater;
import borderPatrol.Data.Board;
import borderPatrol.Data.Move;
import borderPatrol.misc.CFRInformationSet;
import borderPatrol.misc.GameTreeBuilder;

public class CFRPlayer extends Player {
	
	private HashMap<String, CFRInformationSet> informationSets;

	public CFRPlayer(int sign) {
		super(sign);
		this.informationSets = new GameTreeBuilder(new BorderPatrolTreeUpdater()).getGameTree();
	}

	@Override
	public Move getNextMove(Board board) {
		
		Random random = new Random();
		CFRInformationSet set = informationSets.get(board.getId());

		float move = random.nextFloat();

//		System.out.println();
//		System.out.println(set);
//		System.out.println();

		for (int i = 0; i < set.getAverageStrategy().length; i++) {
			move -= set.getAverageStrategy()[i];

			if (move < 0) {
				return set.getMoves().get(i);
			}

		}

		return set.getMoves().getLast();
	}

}
